package manager;

import java.util.ArrayList;

import entity.Section;

/**
 * @author jaslin.wee.2012
 * 
 */

public class CartMgr {

	DatabaseMgr dbMgr;

	public CartMgr() {
		dbMgr = new DatabaseMgr();
	}

	public void addSectionForStudent(String courseCode, String sectionCode,
			String userId) {

		String sql = "insert into cart (courseCode, sectionCode, userId) VALUES (?, ?, ?) ";
		dbMgr.openAndUpdateAndClose(sql, courseCode, sectionCode, userId);
	}

	public ArrayList<Section> retrieveSectionsForStudent(String userId) {

		String sql = "select cart.courseCode as courseCode ,cart.sectionCode as sectionCode,userId, "
				+ "day,startTime,endTime,instructor,venue,size,school, "
				+ "title,description,examDate,examStartTime,examEndTime from cart "
				+ "inner join section_course on cart.courseCode = section_course.courseCode "
				+ "and cart.sectionCode = section_course.sectionCode "
				+ "where cart.userId=?";

		return RetrieveSectiontUtil.retrieveMultipleSectionsForQuery(dbMgr,
				sql, userId);
	}

	public void deleteSectionForStudent(String courseCode, String sectionCode,
			String userId) {

		String sql = "delete from cart where courseCode=? and sectionCode=? and userId=? ";

		dbMgr.openAndUpdateAndClose(sql, courseCode, sectionCode, userId);
	}

}
